package com.xisoft.devise.service.impl;

import com.xisoft.common.io.FileUtilbc;
import com.xisoft.devise.service.FileService;

import java.io.*;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

/**
 * *
 * Created with Description:
 *
 * @version 1.0 <br>
 * @packagename: com.xisoft.devise.service.impl<br>
 * @author: LiBencheng <br>
 * @computer: licheng <br>
 * @date: Created on 2022/9/26 14:07 <br>
 */
public class FileServiceImpl implements FileService
{

    /**
     * @return
     * @throws IOException
     */
    @Override public ByteArrayOutputStream getScriptZip( ) throws IOException
    {
        String patch = "D:\\OneDrive\\src";
        BufferedInputStream bis = null;
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream);
        List< File > sourceFiles = FileUtilbc.listFile(patch);
        byte[] buffer = new byte[4096];

        for (int i = 0; i < sourceFiles.size(); ++i)
        {
            String fileName = ((File) sourceFiles.get(i)).getPath();
            ZipEntry zipEntry = new ZipEntry(fileName);
            zipOutputStream.putNextEntry(zipEntry);
            bis = new BufferedInputStream(new FileInputStream((File) sourceFiles.get(i)), 4096);
            boolean var9 = false;
            int read = 0;
            while ((read = bis.read(buffer)) != -1)
            { zipOutputStream.write(buffer, 0, read); }
        }
        FileUtilbc.flush(outputStream, zipOutputStream);

        return outputStream;
    }
}
